//
//  WD_MyPlayerMaskView.m
//  BUDING
//
//  Created by HanWoonYong on 16/4/9.
//  Copyright © 2016年 HanWoonYong. All rights reserved.
//

#import "WD_MyPlayerMaskView.h"

@implementation WD_MyPlayerMaskView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.topImageView = [[UIImageView alloc] init];
        self.bottomImageView = [[UIImageView alloc] init];
        self.topImageView.userInteractionEnabled = YES;
        self.bottomImageView.userInteractionEnabled = YES;
        self.playTime = [[UILabel alloc] init];
        self.playTime.textColor = [UIColor whiteColor];
        self.playTime.text = @"00:00";
        self.playTime.textAlignment = NSTextAlignmentRight;
        self.playEndTime = [[UILabel alloc] init];
        self.playEndTime.textColor = [UIColor whiteColor];
        self.playEndTime.text = @"00:00";
        
        self.progressView = [[UIProgressView alloc] init];
        self.progressView.progressTintColor = [UIColor colorWithRed:1.000 green:0.444 blue:0.001 alpha:1.000];
        self.progressView.trackTintColor = [UIColor clearColor];
        
        self.playButton = [[UIButton alloc] init];
        [self.playButton setBackgroundImage:[UIImage imageNamed:@"Image-3"] forState:UIControlStateNormal];
        self.backButton = [[UIButton alloc] init];
        [self.backButton setImage:[UIImage imageNamed:@"Image-6"] forState:UIControlStateNormal];
        self.bigButton = [[UIButton alloc] init];
        [self.bigButton setBackgroundImage:[UIImage imageNamed:@"Image-5"] forState:UIControlStateNormal];
    
        self.slider = [[UISlider alloc] init];
        [self.slider setThumbImage:[UIImage imageNamed:@"Image-4"] forState:UIControlStateNormal];
        self.slider.minimumTrackTintColor = [UIColor whiteColor];
        self.slider.maximumTrackTintColor = [UIColor colorWithWhite:0.739 alpha:1.000];
        [self initCAGradientLayer];
        [self addSubview:self.topImageView];
        [self addSubview:self.bottomImageView];
        [self.topImageView addSubview:self.backButton];
        [self.bottomImageView addSubview:self.playButton];
        [self.bottomImageView addSubview:self.bigButton];
        [self.topImageView addSubview:self.playTime];
        [self.bottomImageView addSubview:self.playEndTime];
        [self.bottomImageView addSubview:self.slider];
        [self.bottomImageView addSubview:self.progressView];
    }
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    
    self.topImageView.frame = CGRectMake(0, 0, width, 50);
    self.bottomImageView.frame = CGRectMake(0, height - 50, width, 50);
    self.topLayer.frame = self.topImageView.bounds;
    self.bottomLayer.frame = self.bottomImageView.bounds;
    self.bigButton.frame = CGRectMake(width - 50, 0, 50, 50);
    self.playButton.frame = CGRectMake(10, 10, 30, 30);
    self.backButton.frame = CGRectMake(10, 20, 30, 30);
    self.bigButton.frame = CGRectMake(width - 50, 10, 30, 30);
    self.playTime.frame = CGRectMake(width - 160, 15, 150, 30);
    self.progressView.frame = CGRectMake(self.playButton.frame.size.width+20, 25, width - 110, 10);
    self.slider.frame = self.progressView.frame;
    
}

- (void)initCAGradientLayer
{
    //初始化Bottom渐变层
    self.bottomLayer = [CAGradientLayer layer];
    [self.bottomImageView.layer addSublayer:self.bottomLayer];
    //设置渐变颜色方向
    self.bottomLayer.startPoint = CGPointMake(0, 0);
    self.bottomLayer.endPoint = CGPointMake(0, 1);
    //设定颜色组
    self.bottomLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,
                                            (__bridge id)[UIColor blackColor].CGColor];
    //设定颜色分割点
    self.bottomLayer.locations = @[@(0.0f) ,@(1.0f)];
    
    //初始Top化渐变层
    self.topLayer = [CAGradientLayer layer];
    [self.topImageView.layer addSublayer:self.topLayer];
    //设置渐变颜色方向
    self.topLayer.startPoint = CGPointMake(1, 0);
    self.topLayer.endPoint = CGPointMake(1, 1);
    //设定颜色组
    self.topLayer.colors = @[ (__bridge id)[UIColor blackColor].CGColor,
                                             (__bridge id)[UIColor clearColor].CGColor];
    //设定颜色分割点
    self.topLayer.locations = @[@(0.0f) ,@(1.0f)];
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
